import time


def get_time(func):
    def wrapper(*args, **kwargs):
        func(*args, **kwargs)
    return wrapper







def get_test(func):
    def wrapper(*args, **kwargs):
        func(*args, **kwargs)
    return wrapper


def get_error(func):
    def wrapper(*args, **kwargs):
        try:
            func(*args, **kwargs)
        except Exception as e:
            print(e)
    return wrapper


class GetUrl(object):
    def __init__(self, url, port, name, gender, age, address):
        self.url = url
        self.port = port
        self.name = name
        self.age = age
        self.gender = gender
        self.address = address

    @get_time
    def run(self):
        time.sleep(1)
        list_test = [1, 2, 3]
        current_time = time.strftime("%H:%M:%S", time.localtime())
        print(list_test[2])
        print("------------------")

    @staticmethod
    @get_time
    def test_case(case_url, case_port, case_number):
        formats = (case_url, case_port)
        print("{}:{}".format(formats[0], formats[1]))
        list_result = [i for i in range(10) if i % 2 is 0]
        print(list_result)
        print("case_number: {}".format(case_number))


class TestClassMethod(object):
    """
        # class method  修饰符对应的函数不需要实例化，不需要 self 参数，
        # 但第一个参数需要是表示自身类的 cls 参数，
        # 可以来调用类的属性，类的方法，实例化对象等。
    """
    def __init__(self, bar, age, address):
        self.bar = bar
        self.age = age
        self.address = address

    def func1(self):
        class_tuple = (self.bar, self.age, self.address)
        print("{}, {}, {}".format(class_tuple[0], class_tuple[1], class_tuple[2]))

    @classmethod
    def func2(cls):
        print('func2{}'.format("--------------"))
        cls(bar=1, age=1, address=None).func1()  # 调用 foo 方法


if __name__ == '__main__':
    gu = GetUrl(url="10.9.242.44", port=8082, name=None, gender=None, age=None, address=None)
    gu.run()
    # gu.test_case(case_url="10.9.242.44", case_port="8082", case_number="001")
    # tm = TestClassMethod(bar=1, age=None, address=None)
    # tm.func2()
